package abg.manage.controller.sys;

import abg.core.common.security.Auth;
import abg.core.domain.db.SysMsg;
import abg.core.domain.search.Psh;
import abg.core.domain.sys.SRS;
import abg.core.service.sys.SysMsgService;
import com.mybatisflex.core.paginate.Page;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 系统消息
 */
@Slf4j
@RestController
@RequestMapping("/manage/system/msg")
public class SysMsgController {

    @Resource
    private SysMsgService sysMsgService;

    //用户消息
    @Auth(onlyLogin = true)
    @PostMapping("/userPageData")
    public SRS<Page<Object>> userPageData(SysMsg param, Psh psh) {
        Page<Object> page = sysMsgService.userPageData(param, psh);
        return SRS.bySuccess(page);
    }

    //消息主体
    @PostMapping("/msgPageData")
    public SRS<Page<SysMsg>> msgPageData(SysMsg param, Psh psh) {
        Page<SysMsg> page = sysMsgService.msgPageData(param, psh);
        return SRS.bySuccess(page);
    }

    //
    @PostMapping("/insert")
    public SRS<Object> insert(SysMsg param) {
        boolean b = sysMsgService.insert(param);
        return SRS.bySuccess();
    }

    //
    @Auth(onlyLogin = true)
    @PostMapping("/delete")
    public SRS<Object> delete(String ids) {
        boolean b = sysMsgService.delete(ids);
        return SRS.bySuccess();
    }

    //
    @PostMapping("/info")
    public SRS<Object> info(String id) {
        SysMsg sysMsg = sysMsgService.info(id);
        return SRS.bySuccess();
    }

    //未读消息
    @Auth(onlyLogin = true)
    @PostMapping("/notReadMsgCount")
    public SRS<Object> notReadMsgCount() {
        long count = sysMsgService.notReadMsgCount();
        return SRS.bySuccess(count);
    }

    //读取前几条未读消息
    @Auth(onlyLogin = true)
    @PostMapping("/msgTopList")
    public SRS<SysMsg> msgTopList(String type, int size) {
        List<SysMsg> list = sysMsgService.msgTopList(type, size);
        return SRS.bySuccess(list);
    }

    //全部已读
    @Auth(onlyLogin = true)
    @PostMapping("/readAll")
    public SRS<Object> readAll() {
        boolean b = sysMsgService.readAll();
        return SRS.bySuccess();
    }

    //部分已读
    @Auth(onlyLogin = true)
    @PostMapping("/readBatch")
    public SRS<Object> readBatch(String msgIds) {
        boolean b = sysMsgService.readBatch(msgIds);
        return SRS.bySuccess();
    }


}
